home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DApp / StripPS.cpp < prev   
Text File  |  1996-07-05  |  3KB  |  159 lines

  1. // StripPS.cp
  2. // d.g.gilbert -- simple file filter, strip codes from Postscript file leaving readable text
  3. // demo app for DCLAP app library
  4.  
  5.  
  6. #include "DClap.h"
  7.  
  8. class DMyApp : public DApplication
  9. {
  10. public:
  11.     enum myapptasks {  mStripPS= 1000, kStripPS };
  12.     void IMyApp(void);
  13.     void DoAboutBox();
  14.     void TextDocDemo(void);
  15.     void SetUpMenus(void);    // override
  16.     Boolean IsMyAction(DTaskMaster* action); //override
  17.     void UpdateMenus(void); // override
  18. };
  19.  
  20.  
  21.  
  22. extern "C" short Main(void)
  23. {
  24.   DMyApp* myapp = new DMyApp();
  25.   myapp->IMyApp();
  26.   myapp->Run();
  27.   delete myapp; 
  28.   return 0;
  29. }
  30.  
  31.  
  32. void DMyApp::IMyApp()
  33. {
  34.     IApplication();
  35. }     
  36.  
  37. void DMyApp::DoAboutBox()
  38. {
  39.     char* aboutMe =
  40. "A simple file filter to convert Postscript code"LINEEND
  41. "into readable text."LINEEND
  42. "Strictly a hack, to work on one form of ps code only.";
  43.     DAboutBoxWindow* about = new DAboutBoxWindow(aboutMe); // make instance & it handles rest
  44. }
  45.  
  46. void DMyApp::SetUpMenus()
  47. {
  48.     DApplication::SetUpMenus();
  49.  
  50.     DMenu* sMenu = NewMenu(mStripPS, "Strip PS");
  51.     sMenu->AddItem( kStripPS, "Strip PS file");
  52. }
  53.  
  54.  
  55. void DMyApp::TextDocDemo()
  56. {
  57.     char* filename= (char*) gFileManager->GetInputFileName(".ps","TEXT");
  58.     if (filename) {
  59.         char *cp;
  60.         char    line[256], *endp;
  61.         Boolean inword= false;
  62.  
  63.         gCursor->watch();
  64.         DFile* psf= new DFile(filename,"r");
  65.         if ((cp= StrStr(filename,".ps")) != NULL) *cp= 0;
  66.         filename= StrAppend(filename,".pstripped");
  67.         DFile* stripf= new DFile( filename, "w");
  68.         
  69.         psf->OpenFile();
  70.         stripf->OpenFile();
  71.         while (psf->ReadLine(line, 255) == 0) {
  72.  
  73.             if (inword)
  74.                 cp= line;
  75.             else {
  76.                 cp= strchr(line,'(');
  77.                 if (cp) { cp++; inword= true; }
  78.                 else cp= line;
  79.                 }
  80.                 
  81.             if (inword) {
  82.                 endp= strchr(cp,')');
  83.                 if (endp) { *endp++= '\t'; *endp= '\0'; inword= false; }
  84.                 else endp= strchr(cp,'\0');
  85.                 stripf->WriteLine(cp);
  86.                 }
  87.             else if (StrStr(line,"%ADO") != 0 || StrStr(line," sf") != 0) {
  88.                 stripf->WriteLine("\n");
  89.                 }
  90.             else if (StrStr(line,"%%Page") != 0) {
  91.                 stripf->WriteLine("\n\n\n");
  92.                 }
  93.                 
  94.             }
  95.         psf->CloseFile();
  96.         stripf->CloseFile();
  97.         
  98.         
  99.         Nlm_ParData paratabs = {false,false,false,false,true,0,0}; // tabs==tabs
  100.         short tabstep = 16;
  101.         
  102.         char* shortname= (char*) gFileManager->FilenameFromPath(filename);
  103.         DWindow* win= new DWindow( 0, this, DWindow::document, -1, -1, -10, -10, shortname);
  104.         DTextDocPanel* td= new DTextDocPanel( 0, win, 490, 300);
  105.         td->SetResize( DView::matchsuper, DView::relsuper);
  106.         td->ShowFileFancy(filename, ¶tabs, NULL, Nlm_programFont, tabstep);
  107.         td->suicide(1);
  108.         
  109.         //win->AddOkayCancelButtons();
  110.         win->Open();
  111.         win->suicide(1);
  112.         free(filename);
  113.         gCursor->arrow();
  114.         }
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121. Boolean DMyApp::IsMyAction(DTaskMaster* action) 
  122. {
  123.     DWindow* win;
  124.     
  125.     switch(action->Id()) {
  126.         
  127.                 // some menu item messages
  128.         case DMyApp::kStripPS:
  129.             this->TextDocDemo();
  130.             return true;
  131.  
  132.         case cOKAY:
  133.         case cCANC:
  134.             {
  135.             DButton* but= (DButton*) action; 
  136.             if ( but && ((win= but->GetWindow()) != NULL) ) {
  137.                 if (action->Id() == cOKAY) {
  138.                     // do Okay close handling...
  139.                     }
  140.                 win->CloseAndFree();
  141.                 }
  142.             }
  143.             return true;
  144.        
  145.         default: 
  146.             return DApplication::IsMyAction(action);
  147.         }
  148. }
  149.  
  150.  
  151.  
  152. void DMyApp::UpdateMenus(void)
  153. {
  154.     DApplication::UpdateMenus();
  155.     
  156.     //gViewCentral->EnableView(DMyApp::kSpecial1);
  157.     //gViewCentral->EnableView(DMyApp::kSpecial2);
  158. }
  159.